#ifndef _FLIBRARY_H_
#define _FLIBRARY_H_

#include "FSettings.h"

namespace Font
{

	class Family;
	class Face;
	class FaceHandle;
	class CharMap;
	class GlyphMap;
	class Metrics;
	class Factory;
	class Loader;
	class Log;
	struct UnicodeRange;

	class Library
	{

		friend class FaceHandle;
		friend class CharMap;
		friend class Family;
	
	public:

		Library();
		~Library();

		void SetFactory(Factory* a_Factory);
		Factory* GetFactory();

		void Init();
		void LoadFontsNative();
		void InitFontsFreeType();

		FaceHandle* GetFontHandle(const tb::String& a_Family, unsigned int a_Size, unsigned int a_Properties, CharMap* a_Map = NULL);

		UnicodeRange* GetUnicodeRangeByIdentifier(unsigned int a_Identifier);
		UnicodeRange* GetUnicodeRangeByCharacter(unsigned int a_Character);

		Loader* GetLoaderNative();
		void AddLoader(Loader* a_Loader);

		Face* LoadFontNative(const tb::String& a_FamilyName);
		Face* LoadFontFreeType(const tb::String& a_File);
		Face* LoadFontBM(const tb::String& a_SettingsFile);

		FaceHandle* GetFace(const tb::String& a_Properties);

		CharMap* CreateCharMap();
		CharMap* GetCharMap(const tb::String& a_Name);

		Family* GetFamilyByName(const tb::String& a_Name);
		Family* CreateFamily(const tb::String& a_Name);

		Log* GetLog();
	
	protected:

		Log* m_Log;

		Factory* m_Factory;

		unsigned int* m_UnicodeRangeStart;
		unsigned int* m_UnicodeRangeEnd;
		unsigned int m_UnicodeRangeTotal;

		void _GetFamilyDefault(Family* a_Family, const tb::String& a_Name);
		unsigned int _GetStyle(const tb::String& a_Name);

		std::vector<Loader*> m_Loaders;
		Loader* m_LoaderNative;
		Loader* m_LoaderFreeType;
		Loader* m_LoaderBM;

		tb::Dir* m_FontDir;

		typedef std::map<std::string, Family*> MapFamily;
		typedef std::map<std::string, Family*>::iterator MapFamilyIter;
		std::vector<Family*> m_Families;
		MapFamily m_FamiliesByName;

		std::vector<Text*> m_DisplayLists;

		typedef std::map<std::string, CharMap*> MapCharMap;
		typedef std::map<std::string, CharMap*>::iterator MapCharMapIter;
		std::vector<CharMap*> m_CharMaps;
		MapCharMap m_CharMapsByName;
		CharMap* m_CharMapDefault;

		Library* m_Library;
	
	}; // class Library

}; // namespace Font
	
#endif